import { useRequest, defaultFormatResult } from '@/hooks';

import { getCandidateInfo, getCommunicateInfo } from '@/pages/Recruitment/service';
import { getRecruitmentInfo, getRecruitRelativeInfo } from '@/pages/Recruitment/Hire/service';

import { getPostApplyData } from '@/pages/WorkFlow/services';

export default function useFlowData(hiDataId, needRequest = true) {
    // 获取发起流程前存储的信息,感觉应该公用并前置
    const { data: applyData = {}, loading: applyLoading } = useRequest(() => getPostApplyData(hiDataId), {
        ready: !!hiDataId && needRequest,
        initialData: {},
        ...defaultFormatResult
    });

    // 候选人信息
    const { data: talentInfo = {}, loading: talentLoading } = useRequest(
        () => getCandidateInfo(applyData.candidateId),
        {
            ready: !!applyData.candidateId && needRequest,
            initialData: {},
            ...defaultFormatResult
        }
    );

    // 薪资沟通信息
    const { data: commInfoList = [], loading: commLoading } = useRequest(() => getCommunicateInfo(applyData.employId), {
        ready: !!applyData.employId && needRequest,
        ...defaultFormatResult
    });

    // 录用信息
    const { data: hireInfo = {}, loading: hireLoading } = useRequest(
        () => getRecruitmentInfo({ employId: applyData.employId }),
        {
            ready: !!applyData.employId && needRequest,
            ...defaultFormatResult
        }
    );

    // 录用相关信息
    // 这参数...河里吗
    const { data: recordInfo = {}, recordLoading } = useRequest(
        () => getRecruitRelativeInfo(hireInfo?.auditRecord?.recruitTalentEmploy?.resumeId),
        {
            ready: !!hireInfo?.auditRecord?.recruitTalentEmploy?.resumeId && needRequest,
            ...defaultFormatResult
        }
    );

    const [commInfo = {}] = commInfoList;

    // 为 DiffSalary 组件提供数据
    if (hireInfo?.auditRecord?.recruitTalentEmploy?.employSalaryCurrencyCode) {
        talentInfo.employSalaryCurrencyCode = hireInfo?.auditRecord?.recruitTalentEmploy?.employSalaryCurrencyCode;
    }

    return {
        applyData,
        talentInfo,
        commInfo,
        hireInfo,
        recordInfo,
        loading: applyLoading || talentLoading || commLoading || hireLoading || recordLoading
    };
}
